package com.lw.creational.singleton.lazyMan;

//饿汉式优点：第一次调用才初始化，避免内存浪费。
public class Singleton {
    private static Singleton instance;  
    private Singleton (){}

    //没有synchronized就是线程不安全，这里
    //线程安全synchronized
    public static synchronized Singleton getInstance() {  
    if (instance == null) {  
        instance = new Singleton();  
    }  
    return instance;  
    }  
}